package reader.components;

import java.util.Map;

import reader.xml.XMLContext;
import reader.xml.XMLHelper;

import components.AbstractComponent;
import components.Function;

public class FunctionRW extends AbstractComponentRW {

    private static final String NAME = "name";

    private static final String DISPLAY = "display";

    private static final String PASSWORD = "password";

    public FunctionRW(Map<String, AbstractComponent> opened) {
        super(opened);
    }

    @Override
    public void read(AbstractComponent component, XMLContext context) {
        Function function = (Function) component;
        function.setName(XMLHelper.readStringProperty(context, NAME));
        function.setDisplay(XMLHelper.readStringProperty(context, DISPLAY));
        function.setPassword(XMLHelper.readIntProperty(context, PASSWORD));
        super.read(component, context);
    }

    @Override
    public void write(AbstractComponent component, XMLContext context) {
        Function function = (Function) component;
        XMLHelper.writeProperty(context, NAME, function.getName());
        XMLHelper.writeProperty(context, DISPLAY, function.getDisplay());
        XMLHelper.writeProperty(context, PASSWORD, function.getPassword());
        super.write(component, context);
    }
}
